//
//  PPStrikeThroughCell.m
//  Shopping List
//
//  Created by Tim Isted on 07/10/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PPStrikeThroughCell.h"


@implementation PPStrikeThroughCell

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
    [super drawInteriorWithFrame:cellFrame inView:controlView];
    
    CGFloat middleY = cellFrame.origin.y + (cellFrame.size.height / 2);
    
    NSString *displayedText = [self objectValue];
    NSDictionary *attributes = [NSDictionary 
                                     dictionaryWithObject:[self font] 
                                     forKey:NSFontAttributeName];
    NSSize textSize = [displayedText sizeWithAttributes:attributes];
    CGFloat lineLength = textSize.width + 4.0;
    
    if( lineLength > cellFrame.size.width )
        lineLength = cellFrame.size.width;
    
    NSPoint leftPoint = NSMakePoint(cellFrame.origin.x, middleY);
    NSPoint rightPoint = NSMakePoint(cellFrame.origin.x + lineLength, middleY);
    
    NSBezierPath *straightLine = [NSBezierPath bezierPath];
    [straightLine moveToPoint:leftPoint];
    [straightLine lineToPoint:rightPoint];
    [[NSColor redColor] set];
    [straightLine stroke];
}

@end
